home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / libsrc / c / sys / longjmp.s < prev    next >
Encoding:
Text File  |  1994-08-05  |  1.5 KB  |  62 lines

  1. /* This is file LONGJMP.S */
  2. /*
  3. ** Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. /*
  16. **    jmp_buf:
  17. **     eax ebx ecx edx esi edi ebp esp eip es fs gs ss
  18. **     0   4   8   12  16  20  24  28  32  36 38 40 42
  19. */
  20.  
  21.     .globl    _longjmp /* jmp_buf, int */
  22. _longjmp:
  23.     pushl    %ebp
  24.     movl    %esp,%ebp
  25.  
  26.     movl    8(%ebp),%edi    /* get jmp_buf */
  27.     movl    12(%ebp),%eax    /* store retval in j->eax */
  28.     movl    %eax,0(%edi)
  29.  
  30.     movl    24(%edi),%ebp
  31.  
  32.     pushfl            /* get flags so will only re-enable */
  33.     popl    %ebx        /* interrupts if they were previously */
  34.                 /* enabled */
  35.  
  36.     cli
  37.     movw    42(%edi),%ax
  38.     movw    %ax,%ss
  39.     movl    28(%edi),%esp
  40.     
  41.     pushl    32(%edi)    /* for a ret! */
  42.  
  43.         pushl    %ebx        /* save flags that contain previous */
  44.                 /* interrupt state */
  45.  
  46.     movw    36(%edi),%ax
  47.     movw    %ax,%es
  48.     movw    38(%edi),%ax
  49.     movw    %ax,%fs
  50.     movw    40(%edi),%ax
  51.     movw    %ax,%gs
  52.     movl    0(%edi),%eax
  53.     movl    4(%edi),%ebx
  54.     movl    8(%edi),%ecx
  55.     movl    12(%edi),%edx
  56.     movl    16(%edi),%esi
  57.     movl    20(%edi),%edi
  58.  
  59.     popfl            /* restore previous interrupt state */
  60.  
  61.     ret            /* actually jump to new eip */
  62.